package com.xilihui.xlh.core.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.xilihui.xlh.core.app.BaseApplication;


/**
 *  SharePreference 工具类
 */
public class YSPUtils {

    private static final String FILE_NAME = "qianjirui";//文件名

    private static SharedPreferences sharedPreferences;
    private static SharedPreferences.Editor editor;

    private static SharedPreferences getSharedPreferences(){
        return BaseApplication.get().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    }


    public static void putInt(String key,int value){
        editor = getSharedPreferences().edit();
        editor.putInt(key,value);
        editor.commit();
    }

    public static void putString(String key,String value){
        editor = getSharedPreferences().edit();
        editor.putString(key,value);
        editor.commit();
    }

    public static void putBoolean(String key,boolean value){
        editor = getSharedPreferences().edit();
        editor.putBoolean(key,value);
        editor.commit();
    }

    public static void putFloat(String key,Float value){
        editor = getSharedPreferences().edit();
        editor.putFloat(key,value);
        editor.commit();
    }

    public static void putLong(String key,long value){
        editor = getSharedPreferences().edit();
        editor.putLong(key,value);
        editor.commit();
    }

    public static int getInt(String key){
        return getSharedPreferences().getInt(key,0);
    }

    public static int getInt(String key,int defValue){
        return getSharedPreferences().getInt(key,defValue);
    }

    public static String getString(String key){
        return getSharedPreferences().getString(key,"");
    }

    public static String getString(String key,String defValue){
        return getSharedPreferences().getString(key,defValue);
    }

    public static boolean getBoolean(String key){
        return getSharedPreferences().getBoolean(key,false);
    }

    public static boolean getBoolean(String key,boolean defValue){
        return getSharedPreferences().getBoolean(key,defValue);
    }

    public static Float getFloat(String key){
        return getSharedPreferences().getFloat(key,0);
    }

    public static Float getFloat(String key,float defValue){
        return getSharedPreferences().getFloat(key,defValue);
    }

    public static Long getLong(String key){
        return getSharedPreferences().getLong(key,0);
    }

    public static Long getLong(String key,long defValue){
        return getSharedPreferences().getLong(key,defValue);
    }


    public static void clearAll(){
        editor.clear();
        editor.commit();
    }

}
